﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RentHouse.DTO;
using RentHouse.IService;

namespace RentHouse.Admin.Controllers
{
    public class RolesController : Controller
    {
        public readonly IPermissionService _permissonService;
        public readonly IRolesService _rolesService;
        public RolesController(IPermissionService permission,IRolesService roles)
        {
            this._permissonService = permission;
            this._rolesService = roles;
        }
        public ActionResult Index()
        {   
            return View();
        }

        public ActionResult GetRolesList(int length, int start, string name)
        {
            int count = 0;
            List<RolesAddDTO> list = _rolesService.GetList(length, start, name, ref count);
            var result = new { data = list, recordsTotal = count, recordsFiltered = count};

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Add()
        {
            return View(_rolesService.GetAdd());
        }
        [HttpPost]
        public ActionResult Add(DTO.RolesAddDTO dTO)
        {
            var result = _rolesService.AddRole(dTO);
            return Json(result);
        }
        public ActionResult Edit(long id)
        {
            return View(_rolesService.GetEditRole(id));
        }

        [HttpPost]
        public ActionResult Edit(RolesAddDTO roleEdit)
        {
            var result = _rolesService.Edit(roleEdit);
            return Json(result);

        }

        public ActionResult Delete(long id)
        {
            var result = _rolesService.Delete(id);
            return Json(result);
        }
        public ActionResult Deletes(long [] id)
        {
            var result = _rolesService.Deletes(id);
            return Json(result);
        }
    }
}